﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace QuanLyBanHang_N3A
{
    public partial class FormTheoDoiBH : Form
    {
        public FormTheoDoiBH()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        string LayTenSanPham(string maSP)
        {
            List<SanPhamDTO> ds = new List<SanPhamDTO>();
            SanPhamBUS bus = new SanPhamBUS();
            ds = bus.LayThongTinSanPham(maSP);
            return ds[0].TenSP;
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            List<PhieuBanDTO> ds = new List<PhieuBanDTO>();
            PhieuBanBUS bus = new PhieuBanBUS();
            ds = bus.TheoDoiBanHang(cmbThang.Text, cmbNam.Text);
            if (ds == null)
                MessageBox.Show("Không có dữ liệu");
            int stt = 1;
            for (int i = 0; i < ds.Count; i++)
            {
                List<CTPhieuBanDTO> dsct = new List<CTPhieuBanDTO>();
                CTPhieuBanBUS busct = new CTPhieuBanBUS();
                dsct = busct.TheoDoiBanHang(cmbThang.Text, cmbNam.Text);
                for (int j = 0; j < dsct.Count; j++)
                {
                    string tensp = LayTenSanPham(dsct[j].MaSP);
                    GridViewTheoDoiBH.Rows.Add(stt, ds[i].NgayBH, tensp,dsct[j].SLBan, dsct[j].ThanhTien);
                    stt++;
                }
            }
        }

        private void cmbThang_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GridViewTheoDoiBH.Rows.Clear();
        }

    }
}
